﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Inovout.Business
{
    [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Function")]
    public class Function : IFunction
    {
        private string name;
        public string Name
        {
            get
            {
                return name;
            }
            set { name = value; }
        }
        private string shortcut;
        public string Shortcut
        {
            get { return shortcut; }
            set { shortcut = value; }
        }
        private string hotKey;
        public string HotKey
        {
            get { return hotKey; }
            set { hotKey = value; }
        }

        private Function dependentFunction;
        public Function DependentFunction
        {
            get { return dependentFunction; }
        }

        private FunctionGroup parent;
        public FunctionGroup Parent
        {
            get { return parent; }
            internal set { parent = value; }
        }
        private FunctionGroup owner;
        public FunctionGroup Owner
        {
            get { return owner; }
            protected set { owner = value; }
        }
        private Type workItemType;
        public Type WorkItemType
        {
            get { return workItemType; }
        }
        private static IList<Function> allFuncations = new List<Function>();


        public Function(FunctionGroup owner, Type workItemType)
            : this(owner, workItemType, null)
        {
        }

        public Function(FunctionGroup owner, Type workItemType, Function dependentFunction)
        {
            ArgumentAssert.IsNotNull(workItemType, "workItemType");
            this.owner = owner;
            this.workItemType = workItemType;
            this.dependentFunction = dependentFunction;

            this.name = workItemType.Name.Substring(0, workItemType.Name.LastIndexOf("WorkItem"));
            allFuncations.Add(this);
            functions = new List<Function>();
            if (dependentFunction != null)
            {
                dependentFunction.functions.Add(this);
            }
        }

        private List<Function> functions;
        public Function[] Functions
        {
            get { return functions.ToArray(); }
        }


        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
